Programmers Corner
David Empson
Copyright (c) 1994 Apple Users' Group, Sydney
Republished from Applecations, a publication of the Apple Users' Group, Sydney, Australia.

dempson@actrix.gen.nz
Source: Internet comp.sys.apple2

After booting directly into ProDOS 8, you'll receive an error when trying to allocate memory using the memory manager. This functionality and a work-around is documented in Apple //gs Toolbox Reference 1 (pg 12-17).

The error is returned by the MMStartUp call because MMStartUp is being called from a location which is not inside a valid handle. Bank 0 memory is not allocated if you boot ProDOS-8 directly.

Unfortunately, no sample code for the work around is provided. Here is some sample code in 65816 assembler to do the job.

    clc
    xce
    rep #$30        ;16-bit mode
    stz Bank0Hand    ;Assume we didn't allocate a handle
    stz Bank0Hand+2
    _TLStartUp
    pha
    _MMStartUp
    pla
    bcc GotID
; If MMStartUp returns an error, bank zero hasn't been allocated yet - the user probably cold booted into ProDOS-8. Get a new Application user ID and allocate some of bank zero for myself. This should be freed before exiting (along with the user ID)
    pha
    pea $1000        ;ID type = application
    _GetNewID
    plx
    bcs crash        ;OUCH!
    pha
    pha        ;Result space
    pea $0000
    pea $B800        ;Size
    phx        ;User ID
    pea $C002        ;Fixed address
    pea $0000
    pea $0800        ;Address
    _NewHandle
    plx
    ply
    bcs crash        ;Oh dear - major problem
    stx Bank0Hand
    sty Bank0Hand+2
    pha
    _MMStartUp    ;Try again...
    pla
    bcc GotID
crash        ;Do something ugly

GotID        ;Store your user ID somewhere


THIS CONTENT COPYRIGHT © 2007, APPLE MACINTOSH USERS' GROUP, SYDNEY
Permission has been obtained to make this material available on the Internet.

Permission is hereby granted for non-profit user groups to republish this content.
PLEASE CREDIT THE AUTHOR AND THE SOURCE: Applecations, publication of the Apple Users' Group, Sydney, Australia

THIS PAGE COPYRIGHT © 2007, ANDREW ROUGHAN